package com.workflow.listener;

import com.oa.service.LeaveService;
import com.oa.utils.MyWebUtils;
import org.activiti.engine.delegate.DelegateExecution;
import org.activiti.engine.delegate.ExecutionListener;

/**
 * @Author Str
 * @Date 2021/12/8 10:57
 * @Description :
 */
public class LeaveEndHandler
        implements ExecutionListener {

    private LeaveService leaveService;
    public LeaveEndHandler(){
        //{ps}将 service 的 Bean 装配上来。
        leaveService = MyWebUtils.getBean(LeaveService.class );
    }

    @Override
    public void notify(DelegateExecution exce)
            throws Exception {
        //{1}获取流程变量
        String isCancel = (String)exce.getVariable("cancel");
        String _status = "已办结";  //默认值
        //{2}根据 cancel 变量设置状态
        //   {a}已取消  {b}已办结
        if("true".equals(isCancel)){
            _status = "已取消";
        }
        //{3}获取到流程的实例ID
        String procInstId = exce.getProcessInstanceId();
        //{4}更新流程的状态
        leaveService.updateStatusByInstanceId(procInstId, _status );
        //{5}更新任务ID为  --> null
        // 不用将taskId和办理人置空
//        leaveService.updateAssigneeAndTask(procInstId, null,null);
    }

}
